const express = require("express");
var router = express.Router();
var pool = require("../pool");
router.get("/", (req, res) => {
    var sql = "SELECT * FROM `at_product`";
    pool.query(sql, [], (err, result) => {
        // res.writeHead(200,{
        //   "Access-Control-Allow-Origin":"http://127.0.0.1:5500"
        // });
        res.write(JSON.stringify(result));
        // res.write(JSON.stringify({
        //     pid: result[0].pid,
        //     pname: result[0].pname,
        //     price: result[0].price,
        //     pic: result[0].pic
        // }));
        res.end();

    })

})
router.get("/bottle", (req, res) => {
    var sql = "SELECT * FROM `at_product` WHERE sort='bottle'";
    pool.query(sql, [], (err, result) => {
        
        res.write(JSON.stringify(result));
  
        res.end();

    })

})
router.get("/home", (req, res) => {
    var sql = "SELECT * FROM `at_product` WHERE sort='home'";
    pool.query(sql, [], (err, result) => {
        
        res.write(JSON.stringify(result));
  
        res.end();

    })

})
router.get("/daily", (req, res) => {
    var sql = "SELECT * FROM `at_product` WHERE sort='daily' limit 8";
    pool.query(sql, [], (err, result) => {
        
        res.write(JSON.stringify(result));
  
        res.end();

    })

})
router.get("/banner", (req, res) => {
    var sql = "SELECT * FROM `at_banner`";
    pool.query(sql, [], (err, result) => {
        
        res.write(JSON.stringify(result));
  
        res.end();

    })

})
router.get("/ms", (req, res) => {
    var sql = "SELECT * FROM `at_product` where sort='ms'";
    pool.query(sql, [], (err, result) => {
        
        res.write(JSON.stringify(result));
  
        res.end();

    })

})
module.exports = router;